package com.yunkeji.api.wall.controller;

import com.yunkeji.api.wall.bo.PageLikeWallBo;
import com.yunkeji.api.wall.bo.PubLikeWallBo;
import com.yunkeji.api.wall.service.LikesWallService;
import com.yunkeji.api.wall.vo.LikeWallVo;
import com.yunkeji.common.annotation.RepeatSubmit;
import com.yunkeji.common.core.controller.BaseController;
import com.yunkeji.common.core.domain.R;
import com.yunkeji.common.core.page.TableDataInfo;
import com.yunkeji.dao.domain.BaseId;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.concurrent.TimeUnit;

/**
 * 贴贴墙
 *
 * @author 老张
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/v1/likesWall")
public class LikesWallController extends BaseController {
    private final LikesWallService likesWallService;

    /**
     * 发布
     *
     * @author 老张
     */
    @PostMapping("/pubLikesWall")
    @RepeatSubmit(interval = 60, timeUnit = TimeUnit.SECONDS, message = "操作过快")
    public R pubLikesWall(@RequestBody @Valid PubLikeWallBo bo) {
        likesWallService.pubLikesWall(bo);
        return R.ok();
    }
    /**
     * 删除我的贴贴墙
     *
     * @author 老张
     */
    @PostMapping("/delWall")
    @RepeatSubmit(interval = 60, timeUnit = TimeUnit.SECONDS, message = "操作过快")
    public R delWall(@RequestBody @Valid BaseId bo) {
        likesWallService.delWall(bo);
        return R.ok();
    }

    /**
     * 删除我的贴贴墙
     *
     * @author 老张
     */
    @PostMapping("/delWallAll")
    @RepeatSubmit(interval = 60, timeUnit = TimeUnit.SECONDS, message = "操作过快")
    public R delWallAll() {
        likesWallService.delWallAll();
        return R.ok();
    }

    /**
     * 贴一下/取消贴一下
     *
     * @author 老张
     */
    @PostMapping("/toLike")
    @RepeatSubmit(interval = 10, timeUnit = TimeUnit.SECONDS, message = "操作过快")
    public R toLike(@RequestBody @Valid BaseId baseId) {
        likesWallService.toLike(baseId);
        return R.ok();
    }

    /**
     * 列表
     *
     * @author 老张
     */
    @PostMapping("/list")
    public TableDataInfo<LikeWallVo> list(@RequestBody @Valid PageLikeWallBo bo) {
        return likesWallService.list(bo);
    }
    /**
     * 我的贴贴墙列表
     *
     * @author 老张
     */
    @PostMapping("/listMine")
    public TableDataInfo<LikeWallVo> listMine(@RequestBody @Valid PageLikeWallBo bo) {
        return likesWallService.listMine(bo);
    }
}
